﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Widgetsphere.Autos.API.FacetedNavigation;

namespace TestData
{
    public static class Extensions
    {
        public static ListingItem ToIndexedItem(this Widgetsphere.Autos.EFDAL.Entity.Listing item)
        {
            var retval = new ListingItem();

            retval.AutoID = item.ListingId;
            retval.Description = item.Description;
            retval.Title = item.Title;

            if (item.Condition != null)
                retval.Condition = item.Condition.Name;
            if (item.ExteriorColor != null)
                retval.ExteriorColor = item.ExteriorColor.Name;
            if (item.InteriorColor != null)
                retval.InteriorColor = item.InteriorColor.Name;
            if (item.UserAccount != null)
            {
                if (item.UserAccount.Latitude != null && item.UserAccount.Longitude != null)
                    retval.Location = new HP.Datastore.Common.GeoCode() { Latitude = item.UserAccount.Latitude.Value, Longitude = item.UserAccount.Longitude.Value };
                retval.City = item.UserAccount.City;
                if (item.UserAccount.State != null)
                    retval.State = item.UserAccount.State.Name;
                if (item.UserAccount.Zip != null)
                    retval.ZIP = item.UserAccount.Zip.Name;
            }

            retval.Make = item.MakeModel.Make.Name;
            if (item.Metro != null)
                retval.Metro = item.Metro.Name;
            retval.Mileage = item.Mileage;
            retval.Model = item.MakeModel.Model.Name;
            retval.PostDate = item.ModifiedDate.Value;
            retval.Price = item.Price;
            if (item.Transmission != null)
                retval.Transmission = item.Transmission.Name;
            retval.Year = item.Year;
            retval.VIN = item.Vin;

            return retval;
        }
    }
}